<%@ page language="java" import="java.sql.*, java.util.*, java.math.*" %>

<jsp:useBean id="myUtils" scope="request" class="com.erclab.internal.xpresso.htmlgeneration.util.Clones" />
<jsp:useBean id="myCreator" scope="request" class="com.erclab.internal.xpresso.htmlgeneration.util.ObjectCreator" />

<%@ include file="../jsp-includes/Header.jsp" %>

<%  // ------------------------------------------------------------------
    // Administration utilities
    // * Clone report
    // * Clone form
    // ------------------------------------------------------------------

    // Request parameters
    String action = request.getParameter("action");
    String objectName = request.getParameter("objectName");
    String newName = request.getParameter("newName");

    // Message to display after action
    String message = "";

    // List of objects
    String list[];

    // Action to execute
    if (action != null){
        // Check existence of parameters
        if (newName == null){
            throw new javax.servlet.jsp.JspException ("ERROR 104 New Name for report not specified");
        }

        if (action.equalsIgnoreCase("CloneReport")){
            myUtils.cloneObject(objectName, newName, "Report");
            message = "Report ' " + objectName + " ' created !";
        } else if (action.equalsIgnoreCase("CloneForm")){
            myUtils.cloneObject(objectName, newName, "Form");
            message = "Form ' " + objectName + " ' created !";
        } else if (action.equals("CreateObject")){
            // What objects are goint to be created
            String createForm = request.getParameter("createForm");
            String createReport = request.getParameter("createReport");
            String editLink = request.getParameter("editLink");
            String removeCheckBox = request.getParameter("removeCheckBox");
            String detailLink = request.getParameter("detailLink");
            String createReportDetail = request.getParameter("createReportDetail");
            String tableName = request.getParameter("tableName");
            String sqlQuery = request.getParameter("sqlQuery");
			String sqlQueryDetail = request.getParameter("sqlQueryDetail");

            if (createForm != null){
                if(myCreator.createForm(netId, tableName, newName)){
                    message += "Form " + newName + " created ! <br>";
                } else {
                    throw new javax.servlet.jsp.JspException ("ERROR XXX Creating a form");
                }
            }

            if (createReport != null){
                if(myCreator.createReport(netId, tableName, newName, sqlQuery, "report", editLink, removeCheckBox, detailLink)){
                    message += "Report " + newName + " created ! <br>";
                } else {
                    throw new javax.servlet.jsp.JspException ("ERROR XXX Creating a Report");
                }
            }

            if (createReportDetail != null){
                if(myCreator.createReport(netId, tableName, newName + "Detail", sqlQueryDetail, "reportDetail", null, null, null)){
                    message += "Report " + newName + " detail created ! <br>";
                } else {
                    throw new javax.servlet.jsp.JspException ("ERROR XXX Creating a Report");
                }
            }

        }
    }
%>

<html><!-- InstanceBegin template="/Templates/gedas_template.dwt.asp" codeOutsideHTMLIsLocked="false" -->
<head>
<title>Finance Automated Calculation Tool - gedas USA</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<!-- InstanceBeginEditable name="head" -->
<script language="JavaScript" type="text/JavaScript">
<!--
function formLoaded(){
	document.AutoObjects.checkSql.disabled = true;
	document.AutoObjects.sqlQuery.disabled = true;
	document.AutoObjects.editLink.disabled = true;
	document.AutoObjects.detailLink.disabled = true;
    document.AutoObjects.removeCheckBox.disabled = true;
	document.AutoObjects.sqlQueryDetail.disabled = true;
    document.AutoObjects.checkSqlDetail.disabled = true;
}

function checkBoxes(){
        if (document.AutoObjects.createReport.checked == true){
            document.AutoObjects.removeCheckBox.disabled = false;
            document.AutoObjects.checkSql.disabled = false;
        } else {
            document.AutoObjects.removeCheckBox.disabled = true;
            document.AutoObjects.checkSql.disabled = true;
            document.AutoObjects.sqlQuery.disabled = true;
        }

        if (document.AutoObjects.createReportDetail.checked){
            document.AutoObjects.checkSqlDetail.disabled = false;
        } else {
            document.AutoObjects.checkSqlDetail.disabled = true;
            document.AutoObjects.sqlQueryDetail.disabled = true;
        }
		
        if (document.AutoObjects.checkSql.checked && ! document.AutoObjects.checkSql.disabled ){
            document.AutoObjects.sqlQuery.disabled = false;
        } else {
            document.AutoObjects.sqlQuery.disabled = true;
        }

        if (document.AutoObjects.checkSqlDetail.checked && ! document.AutoObjects.checkSqlDetail.disabled ){
            document.AutoObjects.sqlQueryDetail.disabled = false;
        } else {
            document.AutoObjects.sqlQueryDetail.disabled = true;
        }

        if (document.AutoObjects.createReport.checked == true && document.AutoObjects.createForm.checked == true){
            document.AutoObjects.editLink.disabled = false;
        } else {
            document.AutoObjects.editLink.disabled = true;
        }

        if (document.AutoObjects.createReport.checked == true && document.AutoObjects.createReportDetail.checked == true){
            document.AutoObjects.detailLink.disabled = false;
        } else {
            document.AutoObjects.detailLink.disabled = true;
        }

}

//-->
</script>


<style type="text/css">
<!--
.style1 {font-size: 12px}
-->
</style>
<style type="text/css">
<!--
.style3 {font-weight: bold}
-->
</style>
<style type="text/css">
<!--
.style4 {font-style: italic}
-->
</style>



<!-- InstanceEndEditable -->
<link href="../html/css/Styles_gedas.css" rel="stylesheet" type="text/css">
<meta name="Author" content="Enrique Rodriguez">
</head>

<body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<table width="740" height="100%" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td valign="top"><table width="740" border="0" cellpadding="0" cellspacing="0">
      <tr valign="bottom">
        <td colspan="2" bgcolor="#003366"><img src="../html/images/Top/Top1.gif" width="544" height="24"></td>
        </tr>
      <tr>
        <td height="6" valign="top" bgcolor="#FF0000"><img src="../html/images/Top/Top2.gif" width="544" height="24"></td>
        <td width="200" rowspan="2"><table width="100%" height="55" border="0" cellpadding="0" cellspacing="0">
          <tr>
            <td align="center"><img src="../html/images/Gedas_logo_web.gif" width="140" height="41"></td>
          </tr>
        </table></td>
      </tr>
      <tr>
        <td height="20" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td width="37%" rowspan="2"><a href="/jsp-app/default.jsp"><img src="../html/images/Top/HomeDown.gif" width="76" height="29" border="0"></a></td>
              <td width="18%" rowspan="2"><a href="/jsp-app/Reporting.htm"><img src="../html/images/Top/ReportingDown.gif" width="115" height="29" border="0"></a></td>
              <td rowspan="2"><a href="/jsp-app/Administration.htm"><img src="../html/images/Top/AdminDown.gif" width="82" height="29" border="0"></a></td>
              <td width="26%" height="8
			  "><img src="../html/images/Top/ShadowLine.gif" width="271" height="8"></td>
            </tr>
            <tr>
              <td>&nbsp;</td>
            </tr>
            <tr>
              <td>&nbsp;</td>
              <td>&nbsp;</td>
              <td>&nbsp;</td>
              <td>&nbsp;</td>
            </tr>
        </table></td>
        </tr>
    </table>
      <table width="740"  border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td align="right">&nbsp;  </td>
        </tr>
      </table>
      <table width="740" border="0" cellspacing="0" cellpadding="0">
        <tr valign="top" background="../html/images/Str_BackgroundTop.gif">
          <td width="19" height="27" align="left" background="../html/images/Str_BackgroundLeft.gif"><img src="../html/images/Str_CornetTopLeft.gif" width="19" height="27"></td>
          <td width="99%" height="27" background="../html/images/Str_BackgroundTop.gif"><!-- InstanceBeginEditable name="PageIcon" --> 
                                 <img src="../html/images/gRAD/Icon_AdminTools.gif">
                                  <!-- InstanceEndEditable --></td>
          <td width="19" height="27" align="right" background="../html/images/Str_BackgroundRight.gif"><img src="../html/images/Str_TopRightCornet.gif" width="19" height="27"></td>
        </tr>
        <tr>
          <td width="19" background="../html/images/Str_BackgroundLeft.gif">&nbsp;          </td>
          <td><table width="100%"  border="0" align="center" cellpadding="0" cellspacing="0" class="IndividualReport">
            <tr>
              <td align="center"><strong> <!-- InstanceBeginEditable name="PageTitle" --> 
                                        Admin Tools 
                                        <!-- InstanceEndEditable --> </strong> </td>
            </tr>
            <tr>
              <td align="center"> <!-- InstanceBeginEditable name="PageDescription" --> 
                                        <p>Application Administrator utilities </p>                                     
                                        <!-- InstanceEndEditable --> </td>
            </tr>
            <tr>
              <td>
                <table width="100%"  border="0" cellspacing="0" cellpadding="0">
                  <tr>
                    <td width="140" valign="top">
                      <table width="95%"  border="0" cellspacing="0" cellpadding="0">
                        <tr>
                          <td width="8"><img src="../html/images/OptionsBox/UpLeftCorner.gif" width="8" height="8"></td>
                          <td background="../html/images/OptionsBox/UpBackground.gif"></td>
                          <td width="7" align="right"><img src="../html/images/OptionsBox/UpRightCorner.gif" width="7" height="8"></td>
                        </tr>
                        <tr>
                          <td width="8" background="../html/images/OptionsBox/RightBackground.gif">&nbsp;</td>
                          <td bgcolor="#FFFFF0"><table width="100%"  border="0" cellspacing="0" cellpadding="0">
                              <tr>
                                <td class="OptionsBox">Options:</td>
                              </tr>
                              <tr>
                                <td><!-- InstanceBeginEditable name="Options" --><table width="75%" border="0" cellpadding="0" cellspacing="0" class="ExplanationText">
                                          <tr>
                                            <td width="16%" height="28"><img src="../html/images/gRAD/ArrowOption.gif" width="9" height="16"></td>
                                            <td width="84%"><a href="DynaReport.jsp?reportName=AllReports"><font class="fontOptions">Reports</font></a></td>
                                          </tr>
                                          <tr>
                                            <td height="28"><img src="../html/images/gRAD/ArrowOption.gif" width="9" height="16"></td>
                                            <td><a href="DynaReport.jsp?reportName=ApplicationForms"><font class="fontOptions">Forms</font></a></td>
                                          </tr>
                                          <tr>
                                            <td height="28">&nbsp;</td>
                                            <td>&nbsp;</td>
                                          </tr>
                                          <tr>
                                            <td colspan="2">&nbsp;</td>
                                            </tr>
                                        </table>
                                        <!-- InstanceEndEditable --></td>
                              </tr>
                          </table></td>
                          <td width="7" align="right" background="../html/images/OptionsBox/LeftBackground.gif">&nbsp;</td>
                        </tr>
                        <tr>
                          <td width="8"><img src="../html/images/OptionsBox/downLeftCorner.gif" width="8" height="9"></td>
                          <td background="../html/images/OptionsBox/DownBackground.gif"></td>
                          <td width="7" align="right"><img src="../html/images/OptionsBox/DownRigthCorner.gif" width="7" height="9"></td>
                        </tr>
                      </table>
                      </td>
                    <td width="*"><!-- InstanceBeginEditable name="PageContent" --> 
                                  <table width="100%"  border="0" cellspacing="0" cellpadding="0">
                                    <tr>
                                      <td align="right" class="style1 style3 style4">
                                        <p><%=message%> </p></td>
                                      </tr>
                                    <tr>
                                      <td class="style1 style3 style4">
									  <form name="form1" method="post" action="AdminUtils.jsp">
                                        <br>
                                        <table width="100%"  border="0" cellpadding="0" cellspacing="0" class="IndividualReport">
                                          <tr>
                                            <td>Clone report:</td>
                                          </tr>
                                          <tr>
                                            <td height="1" bgcolor="#CCCCCC"> </td>
                                          </tr>
                                          <tr>
                                            <td>Report to clone: 
                                              <select name="objectName" id="ReportName">
<% // Print list of forms
    list = myUtils.objectList(objectName, "Report");
    for (int i = 0; i < list.length; i++){
%>
    <option value="<%=list[i]%>"><%=list[i]%></option>
<%  }   %>
                                              </select></td>
                                          </tr>
                                          <tr>
                                            <td>New report name: 
                                              <input name="newName" type="text" id="NewName"></td>
                                          </tr>
                                          <tr>
                                            <td><input type="submit" name="Submit" value="Clone &gt;&gt;">
                                              <input name="action" type="hidden" id="Action" value="CloneReport"></td>
                                          </tr>
                                          <tr>
                                            <td height="1" bgcolor="#CCCCCC">											</td>
                                          </tr>
                                        </table>
                                      </form>
                                        <form name="form1" method="post" action="AdminUtils.jsp">
                                          <br>
                                          <table width="100%"  border="0" cellpadding="0" cellspacing="0" class="IndividualReport">
                                            <tr>
                                              <td>Clone form:</td>
                                            </tr>
                                            <tr>
                                              <td height="1" bgcolor="#CCCCCC"> </td>
                                            </tr>
                                            <tr>
                                              <td>Form to clone:
                                                  <select name="objectName" id="formName">
<% // Print list of forms
    list = myUtils.objectList(objectName, "Form");
    for (int i = 0; i < list.length; i++){
%>
    <option value="<%=list[i]%>"><%=list[i]%></option>
<%  }   %>
                                                </select></td>
                                            </tr>
                                            <tr>
                                              <td>New form name:
                                                  <input name="newName" type="text" id="NewName"></td>
                                            </tr>
                                            <tr>
                                              <td><input type="submit" name="Submit2" value="Clone &gt;&gt;">
                                                  <input name="action" type="hidden" id="Action" value="CloneForm"></td>
                                            </tr>
                                            <tr>
                                              <td height="1" bgcolor="#CCCCCC"> </td>
                                            </tr>
                                          </table>
                                        </form>
									    <form action="AdminUtils.jsp" method="post" name="AutoObjects" id="AutoObjects">
									      <table width="100%"  border="0" cellpadding="0" cellspacing="1" class="IndividualReport">
                                            <tr>
                                              <td>Create auto objects: </td>
                                            </tr>
                                            <tr>
                                              <td height="1" bgcolor="#CCCCCC"> </td>
                                            </tr>
                                            <tr>
                                              <td>Create from table:
                                                  <select name="tableName" id="select2">
<% // Print list of tables
    list = myCreator.showtables();
    for (int i = 0; i < list.length; i++){
%>
                                                    <option value="<%=list[i]%>"><%=list[i]%></option>
                                                    <%  }   %>
                                                </select></td>
                                            </tr>
                                            <tr>
                                              <td>New object name:
                                                  <input name="newName" type="text" id="newName2"></td>
                                            </tr>
                                            <tr>
                                              <td>Create form: 
                                                <input name="createForm" type="checkbox" class="noborder" id="form" value="Y" onClick="checkBoxes()">                                                </td>
                                            </tr>
                                            <tr>
                                              <td>Create Report:
                                                <input name="createReport" type="checkbox" class="noborder" id="report2" value="Y" onClick="checkBoxes()"></td>
                                            </tr>
                                            <tr>
                                              <td><table width="100%"  border="0" cellpadding="0" cellspacing="0" class="IndividualReport">
                                                <tr>
                                                  <td width="4%">&nbsp;</td>
                                                  <td width="96%">Create edit link in report:
                                                    <input name="editLink" type="checkbox" class="noborder" value="Y"></td>
                                                </tr>
                                                <tr>
                                                  <td>&nbsp;</td>
                                                  <td>Create remove check box: 
                                                    <input name="removeCheckBox" type="checkbox" class="noborder" value="Y"></td>
                                                </tr>
                                                <tr>
                                                  <td>&nbsp;</td>
                                                  <td>Create link to record detail: 
                                                    <input name="detailLink" type="checkbox" class="noborder" value="Y"></td>
                                                </tr>
                                                <tr>
                                                  <td>&nbsp;</td>
                                                  <td>Customize report based on sql query:
                                                    <input name="checkSql" type="checkbox" class="noborder" id="checkSql" value="checkbox" onClick="checkBoxes()">
                                                    <br>
                                                    <textarea name="sqlQuery" cols="65" rows="4" id="sqlQuery">SQL Query here</textarea></td>
                                                </tr>
                                              </table></td>
                                            </tr>
                                            <tr>
                                              <td>Create Report Detail:                                                
                                                <input name="createReportDetail" type="checkbox" class="noborder" id="reportDetail2" value="Y" onClick="checkBoxes()"></td>
                                            </tr>
                                            <tr>
                                              <td><table width="100%"  border="0" cellpadding="0" cellspacing="0" class="IndividualReport">
                                                <tr>
                                                  <td width="4%">&nbsp;</td>
                                                  <td width="96%">Customize report based on sql query:
                                                      <input name="checkSqlDetail" type="checkbox" class="noborder" id="checkSql2" value="checkbox" onClick="checkBoxes()">
                                                      <br>
                                                      <textarea name="sqlQueryDetail" cols="65" rows="4" id="textarea">SQL Query here</textarea></td>
                                                </tr>
                                              </table></td>
                                            </tr>
                                            <tr>
                                              <td>&nbsp;</td>
                                            </tr>
                                            <tr>
                                              <td><input type="submit" name="Submit22" value="Create &gt;&gt;">
                                                  <input name="action" type="hidden" id="action2" value="CreateObject">
                                                  <!-- Image will call the javascript function formLoaded() onLoad
												  -->
												  <img src="../html/images/gRAD/Spacer.gif" width="1" height="1" onload="formLoaded()">												  </td>
                                            </tr>
                                            <tr>
                                              <td height="1" bgcolor="#CCCCCC"> </td>
                                            </tr>
                                          </table>
									      </form>
									    <p>&nbsp;</p></td>
                                    </tr>
                                  </table>
                                  <!-- InstanceEndEditable --></td>
                  </tr>
              </table></td>
            </tr>
            <tr>
              <td>&nbsp;</td>
            </tr>
          </table></td>
          <td width="19" background="../html/images/Str_BackgroundRight.gif">&nbsp;</td>
        </tr>

        <tr>
          <td colspan="3"><!-- InstanceBeginEditable name="CusomZone" --> <table width="100%"  border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td width="19" valign="top" background="../html/images/Str_BackgroundLeft.gif">&nbsp;</td>
              <td>&nbsp;</td>
              <td width="19" align="right" valign="top" background="../html/images/Str_BackgroundRight.gif">&nbsp;</td>
            </tr>
          </table><!-- InstanceEndEditable --></td>
        </tr>
        <tr>
          <td width="19" align="left" background="../html/images/Str_BackgroundBottom.gif"><img src="../html/images/Str_BottomLeftCorner.gif" width="19" height="18"></td>
          <td align="right" background="../html/images/Str_BackgroundBottom.gif"><img src="../html/images/Str_gedas.gif" width="183" height="18"></td>
          <td width="19" align="right" background="../html/images/Str_BackgroundBottom.gif"><img src="../html/images/Str_BottomRightCorner.gif" width="19" height="18"></td>
        </tr>
      </table>    </td>
  </tr>
  <tr>
    <td valign="bottom"><br>
      <table width="740" height="25" border="0" cellpadding="0" cellspacing="0" bgcolor="#003063">
        <tr>
          <td><table width="100%" border="0" align="center" cellpadding="0" cellspacing="0" class="PageBottom">
            <tr>
              <td width="55" align="center">&nbsp;</td>
              <td align="center">gedas USA 2004 - Finance Automated Calculation Tool <BR>
      Production release: 1.3.4 - <a href="../jsp-app/About.htm"><font color="#FFFFFF">About this release</font></a></td>
              <td width="55" align="center"><a href="../Tutorial/html/index.htm" target="_blank"><img src="../html/images/Button_Help.gif" alt="gFACT Help pages" width="49" height="17" border="0"></a></td>
            </tr>
          </table></td>
        </tr>
      </table></td>
  </tr>
</table>

</body>
<!-- InstanceEnd --></html>
<%@ include file="../jsp-includes/footer.jsp" %>